package Reflect;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.Scanner;

// 反射执行方法
public class MethodDemo {

    public static void main(String[] args) throws Exception{

        Scanner scanner = new Scanner(System.in);
        new Student().playGame();

        System.out.println("请输入实例化类名：");
        String str = "Reflect.Student";
        Class<?> cla = Class.forName(scanner.nextLine());
        Object obj = cla.newInstance();
        String med = "playGame";
        System.out.println("请输入要执行的方法：");
        Method playGame = cla.getMethod(scanner.nextLine());
        playGame.invoke(obj);


    }

}
